import React, { useState, useEffect } from 'react'
import "./Coupon.less"
import Header from "../../components/Header"
import { reqGetcoupon } from "../../http/api"
export default function Coupon() {
    //初始化数据 
    const [n, setN] = useState(0);
    const [coupon, setcoupon] = useState([])

    let arr = ['未使用', '已使用', '已失效']
    useEffect(() => {
        reqGetcoupon().then(res => {
            if (res.data.code === 200) {
                setcoupon(res.data.list[n].content);
            }

        })
    }, [])
    return (
        <div className="coupon">
            <Header title="优惠券" back></Header>
            {
                arr.map((item, index) => (
                    <div className="cou">
                        <div key={item} className={index === n ? 'select' : ''} onClick={() => setN(index)}>{item}</div></div>
                ))
            }
            {
                coupon.map(item => {
                    <div key={item.id}>{item.title}</div>
                })
            }
        </div>
    )
}
